package bancosys.tec.rtm;

import javax.management.InstanceAlreadyExistsException;
import javax.management.ObjectName;

import org.springframework.jmx.export.MBeanExporter;
import org.springframework.jmx.export.UnableToRegisterMBeanException;

/**
 * FIXME (mmr) : this class SHOULD NOT EXIST and will be deleted when all the tests that, for some weird reason, starts the bean factory
 * twice are fixed.
 * 
 * @author Marcio Ribeiro (mmr)
 * @created Dec 15, 2011
 */
public class LenientMBeanExporter extends MBeanExporter {
    /**
     * {@inheritDoc}
     */
    @Override
    protected ObjectName registerBeanNameOrInstance(Object mapValue, String beanKey) {
        try {
            return super.registerBeanNameOrInstance(mapValue, beanKey);
        } catch (UnableToRegisterMBeanException e) {
            if (e.getCause() instanceof InstanceAlreadyExistsException) {
                return null;
            }
            throw e;
        }
    }
}
